#include <iostream>
#include <map>
using namespace std;

int main()
{
    int n;
    cin>>n;
    map<int,int>nums;
    int maxn,maxt=0;
    for (int i=0;i<n;i++)
    {
        int p;
        cin>>p;
        for (int j=0;j<p;j++)
        {
            int res;
            cin>>res;
            if (nums.find(res)==nums.end())
            {
                nums[res]=1;
                if (nums[res]>maxt)
                {
                    maxt=nums[res];
                    maxn=res;
                }
                else if (nums[res]==maxt&&res>maxn)
                {
                    maxn=res;
                }
            }
            else
            {
                nums[res]+=1;
                if (nums[res]>maxt)
                {
                    maxt=nums[res];
                    maxn=res;
                }
                else if (nums[res]==maxt&&res>maxn)
                {
                    maxn=res;
                }
            }
        }
    }
    cout<<maxn<<" "<<maxt;
}